﻿using UnityEngine;
using UnityEngine.UI;
using System;

namespace Launcher
{
    public enum MessageShowType
    {
        None = 0,
        OneButton = 1,
        TwoButton = 2
    }

    /// <summary>
    /// UI加载阶段提示。
    /// </summary>
    public class UILoadAlert : UIBase
    {
        public Button _btn_ok;
        public Button _btn_cancel;

        public Text _label_desc;

        public Action OnOk;
        public Action OnCancel;
        public MessageShowType Showtype = MessageShowType.None;
        public bool AutoClose = true;

        void Start()
        {
            _btn_ok.onClick.AddListener(OnBtnOK);
            _btn_cancel.onClick.AddListener(OnBtnCancel);
        }

        public override void OnEnter(object data)
        {
            _btn_cancel.gameObject.SetActive(false);
            _btn_ok.gameObject.SetActive(false);
            switch (Showtype)
            {
                case MessageShowType.OneButton:
                    _btn_ok.gameObject.SetActive(true);
                    break;
                case MessageShowType.TwoButton:
                    _btn_ok.gameObject.SetActive(true);
                    _btn_cancel.gameObject.SetActive(true);
                    break;
            }

            _label_desc.text = data.ToString();
        }

        private void OnBtnOK()
        {
            if (OnOk == null)
            {
                Debug.LogWarning("UILoadAlert无点击事件");
            }
            else
            {
                OnOk();
            }
            if (AutoClose) _OnClose();
        }

        private void OnBtnCancel()
        {
            if (OnCancel == null)
            {
                Debug.LogWarning("UILoadAlert无点击事件");
            }
            else
            {
                OnCancel();
            }
            if (AutoClose) _OnClose();
        }

        private void _OnClose()
        {
            LauncherMgr.Hide(UIDefine.UILoadAlert);
        }
    }
}